<template>
	<view class="couponPrompt-content" v-if="show">
		<u--image :src="image" :fade="false" height="400"
			mode="aspectFill" @click="handleUseCoupon()"></u--image>
		<view class="close-toast">
			<unt-icon name="icon-guanbi" size="40" color="#fff" @click="closePrompt"></unt-icon>
		</view>
	</view>
</template>

<script>
	import storage from '@/utils/storage'
	import {NewCoupon} from '@/api/coupon/index.js'
	import store from '@/store'
	export default {
		name: "couponPrompt",
		data() {
			return {
				show: false,
				imageId:0,
				image:''
			};
		},
		async mounted() {
			const coupondata=await NewCoupon();
			if(coupondata.data.yoshopImage){
				this.image=coupondata.data.yoshopImage.url;
				this.imageId=coupondata.data.yoshopImage.imageId;
			}
			if(storage.get("use_coupon_imageId")!=this.imageId){
				this.show=true;
			}
		},
		methods: {
			handleUseCoupon(){
				uni.previewImage({
					current: 0,
					urls: [this.image], 
					loop:true
				})
				// this.show = false;
				// this.$unts.navTo('pages_moon/coupon/popup/popup')
			},
			closePrompt() {
				if(store.getters.userId){
					const expiryTime = 10 * 86400
					storage.set("use_coupon_imageId",this.imageId,expiryTime);
				}
				this.show = false;
			}
		}
	}
</script>

<style lang="scss" scoped>
	.couponPrompt-content {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
	}
</style>